var myScroll = new Object();
//flag 0向左滚动 1向上滚动，当向上滚动时moveRight=向下滚动按钮,moveLeft=向上滚动按钮
jQuery.extend(myScroll, {
    getAnimateStyle:function (flag) {
        animateStyle = 'left';
        if (flag && flag == 1) {
            animateStyle = 'top'
        }
        return animateStyle;
    },
    autoRun:function (m,group,flag,scrollArray,scrollCont) {

    },
    init:function (scrollCont, oEventCont, scrollSize, groupCount, groupSize, moveRight, moveLeft, flag, autostart,flagUri,uri,uriObj) {
        var scrollArray = new Array();
		var uriArray = new Array();
		var uriObjs = jQuery(oEventCont);
        var properties = {};
        var l = 0;
        var len = jQuery(oEventCont).length;
        var t = scrollSize * len;
        var group = len / groupCount;
        var m = 0;
        var mod = len % groupCount;
        for (var i = 0; i < group; i++) {
			if(flagUri){
				itemId = jQuery(uriObjs[i]).attr("itemId")
				uriArray[i] = itemId
			}
            if (i == 0) {
                scrollArray[i] = 0;
                var total = groupSize;
            } else {
                total = total + groupSize;
                if (total > t) {
                    if (len % groupCount == 0)
                        scrollArray[i] = groupSize * i;
                    else {
                        scrollArray[i] = groupSize * i - scrollSize * (groupCount - mod);
                    }

                } else {
                    scrollArray[i] = groupSize * i;
                }
            }

        }
        if (moveRight) {
            jQuery(moveRight).click(function () {
                m++;
                if (m >= group) {
                    m = 0;
                }
                if (m == 0) {
					if(flagUri){
						jQuery(uriObj).attr("href",uri+uriArray[0])
					}
                    properties[myScroll.getAnimateStyle(flag)] = 0
                    jQuery(scrollCont).stop();
                    jQuery(scrollCont).animate(properties, 500);
                } else {
                    properties[myScroll.getAnimateStyle(flag)] = -scrollArray[m]
                    jQuery(scrollCont).animate(properties, 500, function () {
                    });
					if(flagUri){
						jQuery(uriObj).attr("href",uri+uriArray[m])
					}
                }
				
            });
        }
        if (moveLeft) {
            jQuery(moveLeft).click(function () {
                var position = jQuery(scrollCont).position();
                if ((position.left + groupSize) < 0) {
                    m--;
                    properties[myScroll.getAnimateStyle(flag)] = -scrollArray[m]
                    jQuery(scrollCont).animate(properties, 500);
					if(flagUri){
						jQuery(uriObj).attr("href",uri+uriArray[m])
					}
                } else {
                    m = 0;
					if(flagUri){
						jQuery(uriObj).attr("href",uri+uriArray[0])
					}
                    properties[myScroll.getAnimateStyle(flag)] = 0
                    jQuery(scrollCont).animate(properties, 500, function () {
                    });
                }
				
            });
        }

        if (autostart && autostart == true) {
            jQuery(scrollCont).hover(function () {
                clearInterval(timerID);
            },function () {
                timerID = setInterval(function(){
                    var properties = {};
                    m++;
                    if (m >= group) {
                        m = 0;
                    }
                    if (m == 0) {
                        properties[myScroll.getAnimateStyle(flag)] = 0
                        jQuery(scrollCont).stop();
                        jQuery(scrollCont).animate(properties, 500);
                    } else {
                        properties[myScroll.getAnimateStyle(flag)] = -scrollArray[m]
                        jQuery(scrollCont).animate(properties, 500, function () {
                        });
                    }
                }, 5000);
            }).mouseout();
        }

    }
})
